// pages/convenient/convenient.js
var Bmob = require('../../utils/Bmob-2.2.0.min.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  franchisee:[],
  inputShowed: false,
  inputVal: "",
  height:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var type=Number(options.type);
    this.getheight();
    this.get_franchiseeList(type);
  },



  getheight:function(){
    var that=this;
    wx.getSystemInfo({
     success:function(res) {
      
      that.setData({
        height: res.windowHeight-46
      })
      }
  })
  },


  showInput: function () {
    this.setData({
      inputShowed: true
    });

  },

  tapPhoneCallHandler: function (e) {

    app.tapPhoneCallHandler(e);
  },

  hideInput: function () {
    var that=this;
    this.setData({
      inputVal: "",
      inputShowed: false
    });
//that.get_franchiseeList();
  },

  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  },

  search:function(e){
    var that = this;
    var search_str=that.data.inputVal;
    //var Franchisee = Bmob.Object.extend("Franchisee");

    var franchisee =Bmob.Query("Franchisee");
   // franchisee.equalTo("Franchisee_type","==", 8);
    franchisee.equalTo("state", "==",true);
   // franchisee.equalTo("Franchisee_title",search_str);
    franchisee.order('createdAt');  //排序

    franchisee.find().then(res=>{
     
        //var goods=res;

        that.setData({
          franchisee: res
        })
    
    });

  },

  turnTofranchiseeDetail: function (e) {
   console.log(e)
   var id=e.currentTarget.dataset.id;
   var franchiseetype = e.currentTarget.dataset.type;
   
    wx.navigateTo({
      url: "../../pages/franchiseeDetail/franchiseeDetail?detail=" + id +"&type="+franchiseetype
   })
  },

  get_franchiseeList: function (type) {
    var that = this;
 
    var franchisee =  Bmob.Query("Franchisee");
    franchisee.equalTo("Franchisee_type","==", type);
    franchisee.equalTo("state","==" ,true);
    franchisee.order('createdAt');  //排序

    franchisee.find().then(res=>{
    
       that.setData({

          franchisee: res

        })
   
    });


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})